{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Question 47\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Define a class named Circle which can be constructed by a radius. The Circle class has a method which can compute the area._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use def methodName(self) to define a method._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Circle:\n",
    "    def __init__(self, r):\n",
    "        self.radius = r\n",
    "\n",
    "    def area(self):\n",
    "        return 3.1416 * (self.radius ** 2)\n",
    "\n",
    "\n",
    "circle = Circle(5)\n",
    "print(circle.area())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 48\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Define a class named Rectangle which can be constructed by a length and width. The Rectangle class has a method which can compute the area._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use def methodName(self) to define a method._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Rectangle:\n",
    "    def __init__(self, l, w):\n",
    "        self.length = l\n",
    "        self.width = w\n",
    "\n",
    "    def area(self):\n",
    "        return self.length * self.width\n",
    "\n",
    "\n",
    "rect = Rectangle(2, 4)\n",
    "print(rect.area())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 49\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Define a class named Shape and its subclass Square. The Square class has an init function which takes a length as argument. Both classes have a area function which can print the area of the shape where Shape's area is 0 by default._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_To override a method in super class, we can define a method with the same name in the super class._**\n",
    "\n",
    "---\n",
    "\n",
    "\n",
    "\n",
    "**Solutions:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "class Shape:\n",
    "    def __init__(self):\n",
    "        pass\n",
    "\n",
    "    def area(self):\n",
    "        return 0\n",
    "\n",
    "\n",
    "class Square(Shape):\n",
    "    def __init__(self, length=0):\n",
    "        Shape.__init__(self)\n",
    "        self.length = length\n",
    "\n",
    "    def area(self):\n",
    "        return self.length * self.length\n",
    "\n",
    "\n",
    "Asqr = Square(5)\n",
    "print(Asqr.area())  # prints 25 as given argument\n",
    "\n",
    "print(Square().area())  # prints zero as default area"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "# Question 50\n",
    "\n",
    "### **Question**\n",
    "\n",
    "> **_Please raise a RuntimeError exception._**\n",
    "\n",
    "---\n",
    "\n",
    "### Hints\n",
    "\n",
    "> **_Use raise to raise an exception._**\n",
    "\n",
    "---\n",
    "\n",
    "**Solution:**"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "ename": "RuntimeError",
     "evalue": "something wrong",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mRuntimeError\u001b[0m                              Traceback (most recent call last)",
      "\u001b[0;32m<ipython-input-1-5fe8f779d579>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mraise\u001b[0m \u001b[0mRuntimeError\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"something wrong\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[0;31mRuntimeError\u001b[0m: something wrong"
     ]
    }
   ],
   "source": [
    "raise RuntimeError(\"something wrong\")"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "---\n",
    "\n",
    "## Conclusion\n",
    "\n",
    "**_Well It seems that the above problems are very much focused on basic concpets and implimantation of object oriented programming.As the concepts are not about to solve any functional problem rather design the structure , so both codes are very much similar in there implimantation part._**"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
